import { defineStore } from "pinia";

interface UserState {
  name: string;
  token: string;
  roles: string[];
}

export const useUserStore = defineStore("user", {
  state: (): UserState => ({
    name: "",
    token: "",
    roles: [],
  }),
  getters: {
    isLoggedIn: (state) => !!state.token,
  },
  actions: {
    async login(credentials: { username: string; password: string }) {
      // 模拟登录
      this.name = credentials.username;
      this.token = "mock-token";
      this.roles = ["admin"];
    },
    logout() {
      this.$reset();
    },
  },
  persist: true,
});
